﻿using System;
using System.Xml;
using System.Windows.Forms;
using System.ComponentModel;

namespace SedionFormDesigner.Infrastructure
{

    /// <summary>
    /// mlh  2011-08-03 
    /// 
    /// 控件属性过滤类
    /// 
    /// 通过读取xml文件里的样式定义，根据控件类型来对应到一种属性样式
    /// </summary>
    public class PropertyFilter
    {
        //这3个用来读取控件的自定义样式
        XmlDocument mXDoc = new XmlDocument();
        XmlNode tmpXNode;
        XmlNodeList tmpXPropLst;

        /// <summary>
        /// 过滤
        /// </summary>
        /// <param name="source">控件实例</param>
        /// <param name="t">控件</param>
        /// <returns></returns>
        public object Filter(object source)
        {
            Type t = TypeDescriptor.GetReflectionType(source);
            string FilterCondition = "Components/Component[@Name=\"" + t.Name + "\"]";
            mXDoc.Load(Application.StartupPath + "\\Components.xml");
            tmpXNode = mXDoc.SelectSingleNode(FilterCondition);
            if (tmpXNode == null) return source;
            tmpXPropLst = tmpXNode.SelectNodes("Propertys/Property");
            object cp = new CustomProperty(source, tmpXPropLst);
            return cp;
        }
    }
}
